//!快速实现 Actuate 接口的声明宏
//!
//!配合 [crate::create_package] 使用
//!

use crate::pkg::Delegate;

#[allow(unused)]
#[derive(Default)]
pub struct MakeDelegators {
    inner: Vec<Box<dyn crate::pkg::Delegate>>,
}

#[allow(unused)]
impl MakeDelegators {
    pub fn add(&mut self, actuator: impl crate::pkg::Delegate + 'static) {
        self.inner.push(Box::new(actuator));
    }
}

#[allow(unused)]
impl Into<Vec<Box<dyn Delegate>>> for MakeDelegators {
    fn into(self) -> Vec<Box<dyn Delegate>> {
        self.inner
    }
}

#[allow(unused)]
impl From<Vec<Box<dyn Delegate>>> for MakeDelegators {
    fn from(val: Vec<Box<dyn Delegate>>) -> Self {
        Self { inner: val }
    }
}

///快速实现 [crate::pkg::Delegate] 接口的声明宏
///
///# Tip
///
///对于实现 [crate::pkg::Delegate] 的对象，应该是一个元组结构体，然后实现 Debug trait
///
///```no_run
///#[derive(Debug)]
///pub struct MyDelegator;
///
///impl Delegate for MyDelegator {
///     // ...
///}
///
///```
///
#[macro_export]
macro_rules! make_delegators {

    () => {{
        $crate::utils::macros::make_delegators::MakeDelegators::default()
    }};


    (@val $a:expr) => {{
        let mut actuators = make_delegators!();
        actuators.add($a);
        actuators
    }};


    (@val $($a:tt),+ $(,)?) => {{
        let mut actuators = make_delegators!();
        $(actuators.add($a);)+
        actuators
    }};


    ($a:tt + $(,)?) => {{
        make_delegators!(@val $a)
    }};

    ($($a:tt),+ $(,)?) => {{
        make_delegators!(@val $($a),+)
    }};
}
